<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\OpenapiLog;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class OpenapiLogController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new OpenapiLog(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('interface');
            $grid->column('method');
            $grid->column('created_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->panel();
                $filter->equal('id')->width(2);
                $filter->equal('interface')->width(4);
                $filter->like('parameter', '参数')->width(4);;
            });
            $grid->disableCreateButton();
            $grid->disableEditButton();
            $grid->disableDeleteButton();
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new OpenapiLog(), function (Show $show) {
            $show->field('id');
            $show->field('interface');
            $show->field('parameter')->unescape()->as(function ($parameter) {
                return '<pre>' . print_r($parameter, true) . '</pre>';
            });
            $show->field('result')->unescape()->as(function ($result) {
                return '<pre>' . print_r($result, true) . '</pre>';
            });
            $show->field('method');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new OpenapiLog(), function (Form $form) {
            $form->display('id');
            $form->text('interface');
            $form->text('parameter');
            $form->text('result');
            $form->text('method');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
